package com.task.web.controller.core;

import javax.annotation.Resource;

import com.task.core.vo.resp.EngineSchemeDetailRespVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.EngineSchemeRequestDTO;
import com.task.core.service.CheckService;
import com.task.core.service.EngineSchemeService;

import io.swagger.annotations.Api;

/**
 * @author 迪迦.
 * @date 2024/11/4 14:30
 */
@Api("")
@RestController
@RequestMapping("/engineScheme")
public class EngineSchemeController extends BaseController {

  @Resource
  private EngineSchemeService engineSchemeService;

  @Resource
  private CheckService checkService;


  @PreAuthorize("@ss.hasPermi('engineScheme:list')")
  @GetMapping("/getEngineSchemeByPage")
  public TableDataInfo getEngineSchemeByPage(EngineSchemeRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(engineSchemeService.getEngineSchemeByPage(request));
  }


  @PreAuthorize("@ss.hasPermi('engineScheme:list')")
  @GetMapping("/getEngineSchemeDetail")
  public AjaxResult getEngineSchemeDetail(EngineSchemeRequestDTO request) {
    return success(engineSchemeService.getEngineSchemeDetail(request.getCode()));
  }


  @PreAuthorize("@ss.hasPermi('engineScheme:option')")
  @GetMapping("/getEngineSchemeForOption")
  public TableDataInfo getEngineSchemeForOption(EngineSchemeRequestDTO request) {
    return getDataTable(engineSchemeService.getEngineSchemeForOption(request));
  }

  @Log(title = "引擎计划管理", businessType = BusinessType.INSERT)
  @PostMapping("/addEngineScheme")
  public AjaxResult addEngineScheme(@RequestBody EngineSchemeRequestDTO request) {
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    engineSchemeService.addEngineScheme(request);
    return success();
  }

  @Log(title = "引擎计划管理", businessType = BusinessType.UPDATE)
  @PutMapping("/modifyEngineScheme")
  public AjaxResult modifyEngine(@RequestBody EngineSchemeRequestDTO request) {
    checkService.check("data_engine_scheme", request.getCode());
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    engineSchemeService.modifyEngineScheme(request);
    return success();
  }

  @Log(title = "引擎计划管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/deleteEngineScheme/{engineSchemeCode}")
  public AjaxResult deleteEngineScheme(@PathVariable String engineSchemeCode) {
    checkService.check("data_engine_scheme", engineSchemeCode);
    engineSchemeService.deleteEngineScheme(engineSchemeCode, SecurityUtils.getLoginUser().getUserId());
    return success();
  }
  @GetMapping ("/getEngineSchemeDetail/{engineSchemeCode}")
  @PreAuthorize("@ss.hasPermi('system:engineScheme:edit')")
  public AjaxResult getEngineSchemeDetail(@PathVariable String engineSchemeCode) {
    checkService.check("data_engine_scheme", engineSchemeCode);
    EngineSchemeDetailRespVo engineSchemeDetailRespVo  = engineSchemeService.getEngineSchemeDetailByCode(engineSchemeCode);
    return success(engineSchemeDetailRespVo);
  }


}
